new Vue({
  el: '#app',
  data() {
    return {
      column: '',
      store: [],
      shop: [],
      form: {
        Sales_Order_SerialNumber: '',
        Store_SerialNumber: '',
        Sales_Date: '',
        Open_ID: '',
        Sales_Amount: '',
        Collection_Amount: '',
        Sales_ID: '',
        Row_Status: '',
        Operation_ID: '',
        Operation_Datetime: '',
        Enterprise_Info_SerialNumber: $.cookie("enterprise"),
        Children: {
          sales_order_detail: [{
            Sales_Order_Detail_SerialNumber: '',
            Sales_Order_SerialNumber: '',
            Article_SerialNumber: '',
            Quantity: 1,
            Unit_Price: '',
            Sales_Unit_Price: '',
            Amount: '',
            Row_Status: '',
            Operation_ID: '',
            Operation_Datetime: '',
          }],
        }
      },
    }
  },
  mounted() {
    const Sales_Order_SerialNumber = sessionStorage.getItem("Sales_Order_SerialNumber")
    this.getData(Sales_Order_SerialNumber)
  },
  methods: {
    getData(Sales_Order_SerialNumber) {
      const _this = this
      $.ajax({
        url: DomainName + '/SalesOrder_Edit',
        type: 'POST',
        data: { Data: Sales_Order_SerialNumber },
        async: false,
        success: function (res) {
          console.log(res);
          _this.form = res.sales_order[0]
          if (!_this.form.Children.sales_order_detail || _this.form.Children.sales_order_detail.length == 0) {
            _this.form.Children.sales_order_detail = [{
              Sales_Order_Detail_SerialNumber: '',
              Sales_Order_SerialNumber: this.form.Sales_Order_SerialNumber,
              Article_SerialNumber: '',
              Quantity: 1,
              Unit_Price: '',
              Sales_Unit_Price: '',
              Amount: '',
              Row_Status: '',
              Operation_ID: '',
              Operation_Datetime: '',
            }]
          }
        }
      })
      // $.ajax({
      //   url: DomainName + '/StoreInfo',
      //   type: 'GET',
      //   data: { action: "jQueryAjax" },
      //   success: function (res) {
      //     for (let i = 0; i < _this.form.Children.sales_unitprice_storescope.length; i++) {
      //       for (let j = 0; j < res.length; j++) {
      //         if (_this.form.Children.sales_unitprice_storescope[i].Store_SerialNumber == res[j].Store_SerialNumber) {
      //           _this.store.push(res[j].Store_Name);
      //         }
      //       }
      //     }
      //   }
      // })
      // $.ajax({
      //   url: DomainName + '/ShopColumn',
      //   type: 'GET',
      //   data: { action: "jQueryAjax" },
      //   success: function (res) {
      //     res = res.filter(function (item) {
      //       return item.ShopColumn_Id == _this.form.ShopColumn_Id
      //     })
      //     _this.column = res[0].name;
      //   }
      // })
      $.ajax({
        url: DomainName + '/ArticleInfo',
        type: 'GET',
        data: { action: "jQueryAjax", token: $.cookie("token") },
        success: function (res) {
          for (let i = 0; i < _this.form.Children.sales_order_detail.length; i++) {
            for (let j = 0; j < res.length; j++) {
              if (_this.form.Children.sales_order_detail[i].Article_SerialNumber == res[j].Article_SerialNumber) {
                _this.shop.push(res[j].Article_Name);
              }
            }
          }
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        }
      })
    }
  }
})